from django.shortcuts import render

# Create your views here.
from auto_perfmmon.models import account
from django.views import View
from django.http import JsonResponse,HttpResponse
import json
class login(View):
	def post(self,request):
		# body_dict = json.loads(request.body.decode())#postman调试
		username = request.POST.get("username")#接受前端请求
		password = request.POST.get("password")
		if username =="" or password=="" :
			result = {"status": 200,
					  "msg": "用户名或密码为空",
					  "data": {
							   }
					  }
			return JsonResponse(result,safe=False)
		else:
			resd=account.objects.all()
			usernames=[]
			for i in resd:
				usernames.append(i.username)
			if username in usernames:
				res=account.objects.get(username=username)
				if res.password==password:
					result = {"status": 200,
							  "msg": "success!",
							  "data": {"username": username,
									   "password": password,
									  }
								}
					return JsonResponse(result,safe=False)
				else:
					result={

						"status":200,
						"msg":"用户名或密码错误",
						"data":{

						}
					}
					return JsonResponse(result,safe=False)
			else:
				result={
					"status":200,
					"msg":"用户信息不存在",
					"data":{

					}
				}
				return JsonResponse(result,safe=False)





